package com.eqdd.yiqidian.ui.mine;

import android.content.Intent;
import android.databinding.DataBindingUtil;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.eqdd.yiqidian.R;
import com.eqdd.yiqidian.RecyclerViewCustom;
import com.eqdd.yiqidian.base.Config;
import com.eqdd.yiqidian.bean.choose.HangyeBean;
import com.eqdd.yiqidian.bean.rebuild.ProjectExpListResultBean;
import com.eqdd.yiqidian.bean.rebuild.ProjectExpListResultBean;
import com.eqdd.yiqidian.bean.rebuild.slimedit.SlimEditChooseBean;
import com.eqdd.yiqidian.bean.rebuild.slimedit.SlimEditEnterBean;
import com.eqdd.yiqidian.bean.rebuild.slimedit.SlimEditTimeBean;
import com.eqdd.yiqidian.bean.utils.MultiChooseBean;
import com.eqdd.yiqidian.http.DialogCallBack;
import com.eqdd.yiqidian.http.HttpConfig;
import com.eqdd.yiqidian.http.HttpResult;
import com.eqdd.yiqidian.ui.base.SlimBaseMultiEditActivity;
import com.eqdd.yiqidian.utils.MultiChooseTestUtil;
import com.eqdd.yiqidian.utils.SingleChooseUtil;
import com.eqdd.yiqidian.utils.ToastUtil;
import com.eqdd.yiqidian.widget.ActionSheetDialog;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.model.Response;

import java.util.ArrayList;
import java.util.List;

import chihane.jdaddressselector.BottomDialog;
import chihane.jdaddressselector.ISelectAble;

/**
 * Created by 吕志豪 on 17-10-12  上午10:21.
 * Github :https://github.com/lvzhihao100
 * E-Mail：1030753080@qq.com
 * 简书 :http://www.jianshu.com/u/6e525b929aac
 */

public class ProjectExpInfoActivity extends SlimBaseMultiEditActivity {


    private RecyclerViewCustom dataBinding;
    private ProjectExpListResultBean bean;

    @Override
    public void initBinding() {
        dataBinding = DataBindingUtil.setContentView(this, R.layout.activity_recyclerview);
        initTopTitleBar(View.VISIBLE, "添加项目经验");
        bean = (ProjectExpListResultBean) getIntent().getSerializableExtra("bean");
        isSave = false;
        isRead = false;
    }


    @Override
    protected RecyclerView initRecyclerView() {
        return dataBinding.recyclerView;
    }

    @Override
    public void itemClick(int p) {

    }

    @Override
    protected void onChooseClick(int position) {
        OkGo.<HttpResult>post(HttpConfig.BASE_URL + HttpConfig.TOGGLE_PROJECT_EXP_OVERT)
                .params("userGuid", user.getGuid())
                .params("projectepid", bean.getId())
                .params("isOvert", setParam(7).equals("不公开") ? 0 : 1)
                .execute(new DialogCallBack<HttpResult>(ProjectExpInfoActivity.this) {
                    @Override
                    public void onSuccess(Response<HttpResult> response) {
                        HttpResult httpResult = response.body();
                        ToastUtil.showShort(httpResult.getMsg());
                        if (httpResult.getStatus() == 200) {
                            setResult(Config.CHANGE);
                        }
                    }
                });
    }

    @Override
    protected void onTimeClick(int position) {
        updateWorkExp();
    }

    @Override
    protected void setEditBeans() {

        datas.add(new SlimEditEnterBean("项目名称", bean.getProjectName(), 0, "请填写"));
        datas.add(new SlimEditEnterBean("所在企业", bean.getOwnedCompany(), 1,  "请填写"));
        datas.add(new SlimEditTimeBean("项目开始时间", bean.getStartTime(), 2, "请选择").setType(Config.YEAR_MONTH_DAY_TYPE));
        datas.add(new SlimEditTimeBean("项目结束时间", bean.getEndTime(), 3, "请选择").setType(Config.YEAR_MONTH_DAY_TYPE));
        datas.add(new SlimEditEnterBean("项目URL地址", bean.getProjectURL(), 4, "请填写"));
        datas.add(new SlimEditEnterBean("项目职责", bean.getDuty(), 5,  "请填写"));

        datas.add(new SlimEditEnterBean("项目描述", bean.getProjectDescription(), 6,  "请填写"));
        datas.add(new SlimEditChooseBean("是否公开", bean.isIsOvert() ? "公开" : "不公开", 7, "请选择", new String[]{"不公开", "公开"}));

    }



    private void updateWorkExp() {
        OkGo.<HttpResult>post(HttpConfig.BASE_URL + HttpConfig.UPDATE_PROJECT_EXP)
                .params("userGuid", user.getGuid())
                .params("projectepid", bean.getId())
                .params("startTime", setParam(2))
                .params("endTime", setParam(3))
                .params("ownedCompany", setParam(1))
                .params("projectName", setParam(0))
                .params("duty", setParam(5))
                .params("projectDescription", setParam(6))
                .params("projectURL", setParam(4))
                .execute(new DialogCallBack<HttpResult>(ProjectExpInfoActivity.this) {
                    @Override
                    public void onSuccess(Response<HttpResult> response) {
                        HttpResult httpResult = response.body();
                        ToastUtil.showShort(httpResult.getMsg());
                        if (httpResult.getStatus() == 200) {

                            setResult(Config.CHANGE);
                        }
                    }
                });
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == Config.INTENT_CONTENT) {
            updateWorkExp();
        }
    }
}
